package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.Card;
import com.stylefeng.guns.modular.pay.service.ICardService;

/**
 * 银行卡控制器
 *
 * @author fengshuonan
 * @Date 2018-09-26 11:04:30
 */
@Controller
@RequestMapping("/apiCard")
public class CardController extends BaseController {

    private String PREFIX = "/pay/apiCard/";

    @Autowired
    private ICardService apiCardService;

    /**
     * 跳转到银行卡首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "apiCard.html";
    }

    /**
     * 跳转到添加银行卡
     */
    @RequestMapping("/apiCard_add")
    public String apiCardAdd() {
        return PREFIX + "apiCard_add.html";
    }

    /**
     * 跳转到修改银行卡
     */
    @RequestMapping("/apiCard_update/{apiCardId}")
    public String apiCardUpdate(@PathVariable Integer apiCardId, Model model) {
        Card apiCard = apiCardService.selectById(apiCardId);
        model.addAttribute("item",apiCard);
        LogObjectHolder.me().set(apiCard);
        return PREFIX + "apiCard_edit.html";
    }

    /**
     * 获取银行卡列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return apiCardService.selectList(null);
    }

    /**
     * 新增银行卡
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Card apiCard) {
        apiCardService.insert(apiCard);
        return SUCCESS_TIP;
    }

    /**
     * 删除银行卡
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer apiCardId) {
        apiCardService.deleteById(apiCardId);
        return SUCCESS_TIP;
    }

    /**
     * 修改银行卡
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Card apiCard) {
        apiCardService.updateById(apiCard);
        return SUCCESS_TIP;
    }

    /**
     * 银行卡详情
     */
    @RequestMapping(value = "/detail/{apiCardId}")
    @ResponseBody
    public Object detail(@PathVariable("apiCardId") Integer apiCardId) {
        return apiCardService.selectById(apiCardId);
    }
}
